package TemplateMethodDomo.example;

/**
 * @author zsh
 * @Description
 * @create 2022-05-09 20:31
 */
public class StringDisplay extends AbstractDisplay {
    private String str;
    private int width;

    public StringDisplay(String str){
        this.str = str;
        this.width = str.getBytes().length;
    }

    public void printLine(){
        System.out.print("+");
        for (int i = 0; i < this.width; i++) {
            System.out.print("-");
        }
        System.out.println("+");
    }

    @Override
    public void open() {
        printLine();
    }

    @Override
    public void print() {
        System.out.println("|" + str + "|");
    }

    @Override
    public void close() {
        printLine();
    }
}
